package com.deke.baby.service.impl;

import java.util.List;

import com.deke.baby.domain.BabyFamily;
import com.deke.baby.domain.BabyFamilyMember;
import com.deke.baby.domain.SignFamilyMember;
import com.deke.baby.mapper.SignFamilyMemberMapper;
import com.deke.baby.vo.BabyFamilyVo;
import com.deke.baby.vo.SignFamilyVo;
import com.deke.common.utils.DateUtils;
import com.deke.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.deke.baby.mapper.SignFamilyMapper;
import com.deke.baby.domain.SignFamily;
import com.deke.baby.service.ISignFamilyService;

/**
 * 活动报名家庭Service业务层处理
 *
 * @author deke
 * @date 2023-06-28
 */
@Service
public class SignFamilyServiceImpl implements ISignFamilyService
{
    @Autowired
    private SignFamilyMapper signFamilyMapper;

    @Autowired
    private SignFamilyMemberMapper signFamilyMemberMapper;

    /**
     * 查询活动报名家庭
     *
     * @param id 活动报名家庭主键
     * @return 活动报名家庭
     */
    @Override
    public SignFamilyVo selectSignFamilyById(Long id)
    {
        SignFamilyVo vo=new SignFamilyVo();
        vo.setSignFamily(signFamilyMapper.selectSignFamilyById(id));
        SignFamilyMember member=new SignFamilyMember();
        member.setSignFamilyId(id);
        vo.setSignFamilyMemberList(signFamilyMemberMapper.selectSignFamilyMemberList(member));
        return vo;
    }

    /**
     * 查询活动报名家庭列表
     *
     * @param signFamily 活动报名家庭
     * @return 活动报名家庭
     */
    @Override
    public List<SignFamily> selectSignFamilyList(SignFamily signFamily)
    {
        return signFamilyMapper.selectSignFamilyList(signFamily);
    }

    /**
     * 新增活动报名家庭
     *
     * @param vo 活动报名家庭
     * @return 结果
     */
    @Override
    public void insertSignFamily(SignFamilyVo vo)
    {
        SignFamily signFamily=  vo.getSignFamily();

        signFamilyMapper.insertSignFamily(signFamily);
        for (SignFamilyMember m:vo.getSignFamilyMemberList()) {
            m.setSignFamilyId(signFamily.getId());
            signFamilyMemberMapper.insertSignFamilyMember(m);
        }

    }

    /**
     * 修改活动报名家庭
     *
     * @param vo 活动报名家庭
     * @return 结果
     */
    @Override
    public void updateSignFamily(SignFamilyVo vo)
    {
        SignFamily signFamily=  vo.getSignFamily();
        signFamilyMapper.updateSignFamily(signFamily);
        signFamilyMemberMapper.deleteSignFamilyMemberById(signFamily.getId());
        for (SignFamilyMember m:vo.getSignFamilyMemberList()) {
            m.setSignFamilyId(signFamily.getId());
            signFamilyMemberMapper.insertSignFamilyMember(m);
        }
    }

    /**
     * 批量删除活动报名家庭
     *
     * @param ids 需要删除的活动报名家庭主键
     * @return 结果
     */
    @Override
    public int deleteSignFamilyByIds(Long[] ids)
    {
        return signFamilyMapper.deleteSignFamilyByIds(ids);
    }

    /**
     * 删除活动报名家庭信息
     *
     * @param id 活动报名家庭主键
     * @return 结果
     */
    @Override
    public int deleteSignFamilyById(Long id)
    {
        return signFamilyMapper.deleteSignFamilyById(id);
    }
}
